<?php
namespace Admin\Controller;
use Think\Controller;
//猜歌送红包
class GuessNewSongController extends CommonController {
    const AppID     =   'wx370386b7eb0c04bc';
    const AppSecret =   '25d7798f008b06ec3641d5e709599600';

    public function index(){
        self::user_list();
    }

    /**
     * 发送消息模板
     */

    public function send(){


        if (IS_AJAX)
        {

            $tem = I('post.tem','','htmlspecialchars');
            $keyword1 = I('post.keyword1','','htmlspecialchars');
            $keyword2 = I('post.keyword2','','htmlspecialchars');
            $keyword3 = I('post.keyword3','','htmlspecialchars');
            $keyword4 = I('post.keyword4','','htmlspecialchars');
            $keyword5 = I('post.keyword5','','htmlspecialchars');
            $emphasis_keyword = I('post.emphasis_keyword','','htmlspecialchars');
            $touser = I('post.touser','','htmlspecialchars');
            $uid = I('post.uid','','int');

            if ($uid){
                $touser = M('newsong_member')->where(array('uid'=>$uid))->getField('openid');
            }


            $data = array();
            if ($keyword1){
                $data['keyword1'] = array(
                    'value'=>$keyword1,
                    'color'=>'#173177',
                );
            }

            if ($keyword2){
                $data['keyword2'] = array(
                    'value'=>$keyword2,
                    'color'=>'#173177',
                );
            }

            if ($keyword3){
                $data['keyword3'] = array(
                    'value'=>$keyword3,
                    'color'=>'#173177',
                );
            }

            if ($keyword4){
                $data['keyword4'] = array(
                    'value'=>$keyword4,
                    'color'=>'#173177',
                );
            }

            if ($keyword5){
                $data['keyword5'] = array(
                    'value'=>$keyword5,
                    'color'=>'#173177',
                );
            }
            $appid = "wx370386b7eb0c04bc";
            $secret = "25d7798f008b06ec3641d5e709599600";
            if ($tem){
                $res = $this->sendtem($appid,$secret,$tem,$data,$emphasis_keyword,$touser);
            }else{
                $res = 0;
            }


            if (!empty($res))
            {
                $msg['state']   =   200;
                $msg['error']   =   '发送成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '发送失败';
                $this->ajaxReturn ($msg,'JSON');
            }


        }

        $this->display('send');

    }
        //排行
    public function game_rank(){

        $today_time             =   strtotime(date('Y-m-d'));
        $where                  =   array();
        $where['create_time']   =   array('EGT',$today_time);
        $where['status']        =   1;
        $data   =   M('newsong_activity_record')->where($where)->field("min(time) as time,nickname,avatarurl,uid,id,service_time")->group('uid')->order(array('time'=>'asc'))->select();

        $this->assign('data',$data);
        $this->display('game_rank');

    }

    //删除某个挑战记录
    public function game_delrank(){

        if (IS_AJAX){

            $where['id'] = I('post.id','','htmlspecialchars');

            if (empty($where['id']))
            {
                $msg['state']   =   -1;
                $msg['error']   =   '非法请求';
                $this->ajaxReturn ($msg,'JSON');
            }

            $del = M('newsong_activity_record')->where($where)->delete();


            if (!empty($del))
            {
                $msg['state']   =   200;
                $msg['error']   =   '删除成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '删除失败';
                $this->ajaxReturn ($msg,'JSON');
            }


        }
    }
        //更新挑战时间
    public function game_rank_edit()
    {
        if (IS_AJAX)
        {
            $where['id']  =   I('post.id','','htmlspecialchars');
            if (empty($where['id']))
            {
                $msg['state']   =   -1;
                $msg['error']   =   '非法请求';
                $this->ajaxReturn ($msg,'JSON');
            }

            $data['time']     =   I('post.time','','htmlspecialchars');

            $result     =   M('newsong_activity_record')->where($where)->save($data); // 根据条件更新记录

            //记录相关操作日志

            if (!empty($result))
            {
                $msg['state']   =   200;
                $msg['error']   =   '更新成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '更新失败';
                $this->ajaxReturn ($msg,'JSON');
            }
        }
        else
        {
            $where['id']  =   I('get.id','','htmlspecialchars');

            if (empty($where['id']))
            {
                $this->error('非法请求');
            }

            $data  =   M('newsong_activity_record')->where($where)->find();

            if ( empty($data))
            {
                $this->error('数据不存在');
            }

            $this->assign("data",$data);
            $this->display('game_rank_edit');
        }
    }

    /**
     * 缓存到文件
     */
    private function cachenewsong(){

        $cache = S('admincachenewsong');

        if (!empty($cache)){
            return $cache;
        }

        $info = M('newsong_template_send')->field('wxopen_template_send_id,appid,secret,touser,template_id,page,form_id')->where(array('status'=>'-1'))->group('uid')->order('wxopen_template_send_id desc')->select();

        $data = array();
//        foreach ($info as $key=>$value){
//
//            $data[$value['touser']] = $value;
//
//        }

        S('admincachenewsong',$info,7200*24*10);

        return S('admincachenewsong');

    }

    /**
     * 消息推送
     * @return int
     */
    private function sendtem($appid,$secret,$template_id,$fdata,$emphasis_keyword,$touser){


        if ($touser){
            $where2['status'] = '-1';
            $where2['touser'] = $touser;
            $info = M('newsong_template_send')->field('wxopen_template_send_id,appid,touser,template_id,page,form_id')->where($where2)->limit(1)->order('wxopen_template_send_id desc')->select();
        }else{
            $info = $this->cachenewsong();
        }

        $access_token = $this->gettoken($appid,$secret);
        $code = 0;
        foreach ($info as $key=>$value){


            $data = array(
                'touser'=>$value['touser'],
                'template_id'=>$template_id,
                'page'=>'pages/index/index',
                'form_id'=>$value['form_id'],
                'data'=>$fdata,
                'emphasis_keyword'=>$emphasis_keyword
            );
            $res = $this->sendtemp($access_token,$data);
            $save = array(
                'errcode'=>$res['errcode'],
                'errmsg'=>$res['errmsg'],
                'data'=>json_encode($data['data']),
                'emphasis_keyword'=>$data['emphasis_keyword'],
            );

            S('test',$res['errcode']);
            if ($res['errcode']==0){
                $save['status'] = 1;
                $code = 1;

              //  M('newsong_template_send')->where(array('wxopen_template_send_id'=>$value['wxopen_template_send_id']))->save($save);
            }else{
                $save['status'] = 2;
               // M('newsong_template_send')->where(array('wxopen_template_send_id'=>$value['wxopen_template_send_id']))->save($save);
            }

        }

        return $code;

    }

    /**
     * 发送模板消息
     */
    private function sendtemp($access_token,$data){

        $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=$access_token";

        $res = $this->getcomponent($url,json_encode($data,true));

        return $res;

    }

    //用户模块
    public function user_list()
    {

        $User       =   M('newsong_member'); // 实例化User对象

        $where = array();
        $where['uid'] = I('get.uid','','int');
        $where['prize_num'] = I('get.prize_num','','int');

        $nickname = I('get.nickname','','htmlspecialchars');

        if ($nickname){
            $where['nickname'] = array('like',"%$nickname%");
        }

        $where                              =   array_filter($where);

        $sum = array();
        $this->assign('name',1);
        $this->assign("title","空耳军(猜歌名大师)");
        if (!empty($where)){

            $count      =   $User->where($where)->count();// 查询满足要求的总记录数
            $Page       =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
            $show       =   $Page->show();// 分页显示输出

            $field      =   array('uid','nickname','avatarurl','province','city','game_num','prize_num','totle_num','money_total','total_money','lock_money','login_num','create_time','login_time','appid');
            $data['user_list'] = $User->field($field)->where($where)->order('uid desc')->limit($Page->firstRow.','.$Page->listRows)->select();

            foreach ($data['user_list'] as $key=>$val){

                $data['user_list'][$key]['frendnum'] = M('newsong_relationship')->where(array('my_member_id'=>$val['uid']))->count();
                $data['user_list'][$key]['sharegroup']  = M('newsong_wechat_group')->where(array('uid'=>$val['uid']))->count();

                $sum['frendnum'] += $data['user_list'][$key]['frendnum'];
                $sum['sharegroup'] += $data['user_list'][$key]['sharegroup'];
                $sum['game_num'] +=$val['game_num'];
                $sum['prize_num'] +=$val['prize_num'];
                $sum['totle_num'] +=$val['totle_num'];

                if ($val['appid']=='wx47f3a2edad028bdf'){
                    $data['user_list'][$key]['title'] = '猜歌名大师奖金版';
                }elseif($val['appid']=='wx370386b7eb0c04bc'){
                    $data['user_list'][$key]['title'] = '空耳军';
                }

                $sum['money_total'] +=$val['money_total'];

                $sum['total_money'] +=$val['total_money'];

                $sum['lock_money'] +=$val['lock_money'];
            }
            $sum['money_total'] = sprintf("%.2f",$sum['money_total']);
            $sum['total_money'] = sprintf("%.2f", $sum['total_money']);

            $this->assign('page',$show);// 赋值分页输出
            $this->assign("data",$data);
            $this->assign("sum",$sum);
            $this->display('user_list');
        }else {
            $count      =   $User->count();// 查询满足要求的总记录数
            $Page       =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
            $show       =   $Page->show();// 分页显示输出

            $field      =   array('uid','nickname','avatarurl','province','city','game_num','prize_num','totle_num','money_total','total_money','lock_money','login_num','create_time','login_time','appid');
            $data['user_list'] = $User->field($field)->order('uid desc')->limit($Page->firstRow.','.$Page->listRows)->select();

            foreach ($data['user_list'] as $key=>$val){

                $data['user_list'][$key]['frendnum'] = M('newsong_relationship')->where(array('my_member_id'=>$val['uid']))->count();
                $data['user_list'][$key]['sharegroup']  = M('newsong_wechat_group')->where(array('uid'=>$val['uid']))->count();

                $sum['frendnum'] += $data['user_list'][$key]['frendnum'];
                $sum['sharegroup'] += $data['user_list'][$key]['sharegroup'];
                $sum['game_num'] +=$val['game_num'];
                $sum['prize_num'] +=$val['prize_num'];
                $sum['totle_num'] +=$val['totle_num'];

                if ($val['appid']=='wx47f3a2edad028bdf'){
                    $data['user_list'][$key]['title'] = '猜歌名大师奖金版';
                }elseif($val['appid']=='wx370386b7eb0c04bc'){
                    $data['user_list'][$key]['title'] = '空耳军';
                }
                $sum['money_total'] +=$val['money_total'];

                $sum['total_money'] +=$val['total_money'];

                $sum['lock_money'] +=$val['lock_money'];
            }
            $sum['money_total'] = sprintf("%.2f",$sum['money_total']);
            $sum['total_money'] = sprintf("%.2f", $sum['total_money']);


            $this->assign("sum",$sum);
            $this->assign('page',$show);// 赋值分页输出
            $this->assign("data",$data);
            $this->display('user_list');
        }

    }

    //用户模块疯狂猜歌
    public function user_listplus()
    {

        $User       =   M('newsongplus_member'); // 实例化User对象

        $where = array();
        $where['uid'] = I('get.uid','','int');
        $where['prize_num'] = I('get.prize_num','','int');
        $nickname = I('get.nickname','','htmlspecialchars');

        if ($nickname){
            $where['nickname'] = array('like',"%$nickname%");
        }

        $where                              =   array_filter($where);

        $sum = array();
        $this->assign('name',2);
        $this->assign("title","疯狂猜歌");
        if (!empty($where)){

            $count      =   $User->where($where)->count();// 查询满足要求的总记录数
            $Page       =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
            $show       =   $Page->show();// 分页显示输出

            $field      =   array('uid','nickname','avatarurl','province','city','game_num','prize_num','totle_num','money_total','total_money','lock_money','login_num','create_time','login_time');
            $data['user_list'] = $User->field($field)->where($where)->order('uid desc')->limit($Page->firstRow.','.$Page->listRows)->select();

            foreach ($data['user_list'] as $key=>$val){

                $data['user_list'][$key]['frendnum'] = M('newsongplus_relationship')->where(array('my_member_id'=>$val['uid']))->count();
                $data['user_list'][$key]['sharegroup']  = M('newsongplus_wechat_group')->where(array('uid'=>$val['uid']))->count();
                $data['user_list'][$key]['title'] = '疯狂猜歌';
                $sum['frendnum'] += $data['user_list'][$key]['frendnum'];
                $sum['sharegroup'] += $data['user_list'][$key]['sharegroup'];
                $sum['game_num'] +=$val['game_num'];
                $sum['prize_num'] +=$val['prize_num'];
                $sum['totle_num'] +=$val['totle_num'];

                $sum['money_total'] +=$val['money_total'];

                $sum['total_money'] +=$val['total_money'];

                $sum['lock_money'] +=$val['lock_money'];
            }
            $sum['money_total'] = sprintf("%.2f",$sum['money_total']);
            $sum['total_money'] = sprintf("%.2f", $sum['total_money']);

            $this->assign('page',$show);// 赋值分页输出
            $this->assign("data",$data);
            $this->assign("sum",$sum);
            $this->display('user_list');
        }else {
            $count      =   $User->count();// 查询满足要求的总记录数
            $Page       =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
            $show       =   $Page->show();// 分页显示输出

            $field      =   array('uid','nickname','avatarurl','province','city','game_num','prize_num','totle_num','money_total','total_money','lock_money','login_num','create_time','login_time');
            $data['user_list'] = $User->field($field)->order('uid desc')->limit($Page->firstRow.','.$Page->listRows)->select();

            foreach ($data['user_list'] as $key=>$val){

                $data['user_list'][$key]['frendnum'] = M('newsongplus_relationship')->where(array('my_member_id'=>$val['uid']))->count();
                $data['user_list'][$key]['sharegroup']  = M('newsongplus_wechat_group')->where(array('uid'=>$val['uid']))->count();
                $data['user_list'][$key]['title'] = '疯狂猜歌';
                $sum['frendnum'] += $data['user_list'][$key]['frendnum'];
                $sum['sharegroup'] += $data['user_list'][$key]['sharegroup'];
                $sum['game_num'] +=$val['game_num'];
                $sum['prize_num'] +=$val['prize_num'];
                $sum['totle_num'] +=$val['totle_num'];

                $sum['money_total'] +=$val['money_total'];

                $sum['total_money'] +=$val['total_money'];

                $sum['lock_money'] +=$val['lock_money'];
            }
            $sum['money_total'] = sprintf("%.2f",$sum['money_total']);
            $sum['total_money'] = sprintf("%.2f", $sum['total_money']);

            $this->assign("sum",$sum);
            $this->assign('page',$show);// 赋值分页输出
            $this->assign("data",$data);
            $this->display('user_list');
        }

    }

    //用户模块
    public function user_listnao()
    {

        $User       =   M('naosong_member'); // 实例化User对象

        $where = array();
        $where['uid'] = I('get.uid','','int');
        $where['prize_num'] = I('get.prize_num','','int');

        $nickname = I('get.nickname','','htmlspecialchars');

        if ($nickname){
            $where['nickname'] = array('like',"%$nickname%");
        }

        $where                              =   array_filter($where);

        $sum = array();
        $this->assign('name',3);
        $this->assign("title","脑筋猜歌");
        if (!empty($where)){

            $count      =   $User->where($where)->count();// 查询满足要求的总记录数
            $Page       =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
            $show       =   $Page->show();// 分页显示输出

            $field      =   array('uid','nickname','avatarurl','province','city','game_num','prize_num','totle_num','money_total','total_money','lock_money','login_num','create_time','login_time');
            $data['user_list'] = $User->field($field)->where($where)->order('uid desc')->limit($Page->firstRow.','.$Page->listRows)->select();

            foreach ($data['user_list'] as $key=>$val){

                $data['user_list'][$key]['frendnum'] = M('naosong_relationship')->where(array('my_member_id'=>$val['uid']))->count();
                $data['user_list'][$key]['sharegroup']  = M('naosong_wechat_group')->where(array('uid'=>$val['uid']))->count();
                $data['user_list'][$key]['title'] = '脑筋猜歌';

                $sum['frendnum'] += $data['user_list'][$key]['frendnum'];
                $sum['sharegroup'] += $data['user_list'][$key]['sharegroup'];
                $sum['game_num'] +=$val['game_num'];
                $sum['prize_num'] +=$val['prize_num'];
                $sum['totle_num'] +=$val['totle_num'];

                $sum['money_total'] +=$val['money_total'];

                $sum['total_money'] +=$val['total_money'];

                $sum['lock_money'] +=$val['lock_money'];
            }
            $sum['money_total'] = sprintf("%.2f",$sum['money_total']);
            $sum['total_money'] = sprintf("%.2f", $sum['total_money']);
            $this->assign('page',$show);// 赋值分页输出
            $this->assign("data",$data);
            $this->assign("sum",$sum);
            $this->display('user_list');
        }else {
            $count      =   $User->count();// 查询满足要求的总记录数
            $Page       =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
            $show       =   $Page->show();// 分页显示输出

            $field      =   array('uid','nickname','avatarurl','province','city','game_num','prize_num','totle_num','money_total','total_money','lock_money','login_num','create_time','login_time');
            $data['user_list'] = $User->field($field)->order('uid desc')->limit($Page->firstRow.','.$Page->listRows)->select();

            foreach ($data['user_list'] as $key=>$val){

                $data['user_list'][$key]['frendnum'] = M('naosong_relationship')->where(array('my_member_id'=>$val['uid']))->count();
                $data['user_list'][$key]['sharegroup']  = M('naosong_wechat_group')->where(array('uid'=>$val['uid']))->count();
                $data['user_list'][$key]['title'] = '脑筋猜歌';
                $sum['frendnum'] += $data['user_list'][$key]['frendnum'];
                $sum['sharegroup'] += $data['user_list'][$key]['sharegroup'];
                $sum['game_num'] +=$val['game_num'];
                $sum['prize_num'] +=$val['prize_num'];
                $sum['totle_num'] +=$val['totle_num'];

                $sum['money_total'] +=$val['money_total'];

                $sum['total_money'] +=$val['total_money'];

                $sum['lock_money'] +=$val['lock_money'];
            }
            $sum['money_total'] = sprintf("%.2f",$sum['money_total']);
            $sum['total_money'] = sprintf("%.2f", $sum['total_money']);

            $this->assign("sum",$sum);
            $this->assign('page',$show);// 赋值分页输出
            $this->assign("data",$data);
            $this->display('user_list');

        }

    }


    //更多好玩
    public function game_more()
    {
        $data['game_list']  =   M('newsong_app')->select();
        $this->assign("data",$data);
        $this->display('game_more');
    }

    public function game_more_add()
    {
        if (IS_AJAX) 
        {
            $data['appid']     =   I('post.appid','','htmlspecialchars');
            $data['url']       =   I('post.url','','htmlspecialchars');
            $data['envversion']=   I('post.envversion','','htmlspecialchars');
            $data['logo']      =   I('post.logo','','htmlspecialchars');
            $data['content']   =   I('post.content','','htmlspecialchars');
            $data['isshow']    =   I('post.isshow','','htmlspecialchars');
            $data['title']     =   I('post.title','','htmlspecialchars');

            $result     =   M('newsong_app')->data($data)->add(); // 根据条件更新记录

            //记录相关操作日志

            if (!empty($result)) 
            {
                $msg['state']   =   200;
                $msg['error']   =   '添加成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '添加失败';
                $this->ajaxReturn ($msg,'JSON');
            }
        }
        else
        {
            $this->display('game_more_add');
        }
    }

    public function game_more_edit()
    {
        if (IS_AJAX) 
        {
            $where['newsong_app_id']  =   I('post.newsong_app_id','','htmlspecialchars');
            if (empty($where['newsong_app_id']))
            {
                $msg['state']   =   -1;
                $msg['error']   =   '非法请求';
                $this->ajaxReturn ($msg,'JSON');    
            }

            $data['appid']     =   I('post.appid','','htmlspecialchars');
            $data['url']       =   I('post.url','','htmlspecialchars');
            $data['envversion']=   I('post.envversion','','htmlspecialchars');
            $data['logo']      =   I('post.logo','','htmlspecialchars');
            $data['content']   =   I('post.content','','htmlspecialchars');
            $data['isshow']    =   I('post.isshow','','htmlspecialchars');
            $data['title']     =   I('post.title','','htmlspecialchars');

            $result     =   M('newsong_app')->where($where)->save($data); // 根据条件更新记录

            //记录相关操作日志

            if (!empty($result)) 
            {
                $msg['state']   =   200;
                $msg['error']   =   '更新成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '更新失败';
                $this->ajaxReturn ($msg,'JSON');
            }
        }
        else
        {
            $where['newsong_app_id']  =   I('get.id','','htmlspecialchars');

            if (empty($where['newsong_app_id']))
            {
                $this->error('非法请求');
            }

            $data['game_info']  =   M('newsong_app')->where($where)->find();

            if ( empty($data)) 
            {
                $this->error('数据不存在');
            }

            $this->assign("data",$data);
            $this->display('game_more_edit');
        }
    }

    /**
     * 底部小程序
     */
    public function game_list()
    {

        $data['game_list']  =   M('newsong_app')->order('sort asc')->select();
        $this->assign("data",$data);
        $this->display('game_list');
    }


    public function game_list_edit()
    {
        if (IS_AJAX)
        {
            $where['newsong_app_id']  =   I('post.newsong_app_id','','htmlspecialchars');
            if (empty($where['newsong_app_id']))
            {
                $msg['state']   =   -1;
                $msg['error']   =   '非法请求';
                $this->ajaxReturn ($msg,'JSON');
            }

            $data['appid']     =   I('post.appid','','htmlspecialchars');
            $data['url']       =   I('post.url','','htmlspecialchars');
            $data['envversion']=   I('post.envversion','','htmlspecialchars');
            $data['clicktitle']   =   I('post.clicktitle','','htmlspecialchars');
            //$data['logo']      =   I('post.logo','','htmlspecialchars');
            $data['content']   =   I('post.content','','htmlspecialchars');
            $data['isshow']    =   I('post.isshow','','htmlspecialchars');
            $data['category']  =   I('post.category','','htmlspecialchars');
            $data['h5show']    =   I('post.h5show','','htmlspecialchars');
            $data['title']     =   I('post.title','','htmlspecialchars');
            $data['sort']     =   I('post.sort','','htmlspecialchars');

            if ($_FILES){
                $setting= C('UPLOAD_SITEIMG_QINIU');
                $setting['savePath'] = 'appshow/newsong/';
                $Upload = new \Think\Upload($setting);
                $info = $Upload->upload($_FILES);
                $file = $info['logo'];
                $data['logo']      =   $file['name'];

                if ($data['logo']){

                    $headimg=M('newsong_app')->where($where)->getField('logo');

                    $Qiniu = new \Think\Upload\Driver\Qiniu\QiniuStorage($setting['driverConfig']);

                    $result = $Qiniu->del($headimg);

                    $error = $Qiniu->errorStr;//错误信息

                }

            }

            $nowsort = M('newsong_app')->where($where)->getField('sort');

            if ($data['sort']!=$nowsort){  //更新的排序不等于原来的排序
                $where1['sort'] = array('egt',$data['sort']);
                $ids = M('newsong_app')->where($where1)->getField('newsong_app_id',true);

                if (!empty($ids)){
                    $ids = array_merge($ids);

                    for ($i=0;$i<count($ids);$i++){

                        M('newsong_app')->where(array('newsong_app_id'=>$ids[$i]))->setInc('sort');  //后面的排序自增
                    }
                }
            }



            $result     =   M('newsong_app')->where($where)->save($data); // 根据条件更新记录

            //记录相关操作日志

            if (!empty($result))
            {
                $msg['state']   =   200;
                $msg['error']   =   '更新成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '更新失败';
                $this->ajaxReturn ($msg,'JSON');
            }
        }
        else
        {
            $where['newsong_app_id']  =   I('get.id','','htmlspecialchars');

            if (empty($where['newsong_app_id']))
            {
                $this->error('非法请求');
            }

            $data['game_info']  =   M('newsong_app')->where($where)->find();

            if ( empty($data))
            {
                $this->error('数据不存在');
            }

            $this->assign("data",$data);
            $this->display('game_list_edit');
        }
    }

    public function game_list_add()
    {
        if (IS_AJAX)
        {
            $data['appid']     =   I('post.appid','','htmlspecialchars');
            $data['url']       =   I('post.url','','htmlspecialchars');
            $data['envversion']=   I('post.envversion','','htmlspecialchars');
            //$data['logo']      =   I('post.logo','','htmlspecialchars');
            $data['content']   =   I('post.content','','htmlspecialchars');
            $data['clicktitle']   =   I('post.clicktitle','','htmlspecialchars');
            $data['isshow']    =   I('post.isshow','','htmlspecialchars');
            $data['category']  =   I('post.category','','htmlspecialchars');
            $data['h5show']    =   I('post.h5show','','htmlspecialchars');
            $data['title']     =   I('post.title','','htmlspecialchars');
            $data['sort']     =   I('post.sort','','htmlspecialchars');


            $where['sort'] = array('egt',$data['sort']);

            if ($_FILES){

                $setting= C('UPLOAD_SITEIMG_QINIU');
                $setting['savePath'] = 'appshow/newsong/';
                $Upload = new \Think\Upload($setting);
                $info = $Upload->upload($_FILES);
                $file = $info['logo'];
                $data['logo']      =   $file['name'];

            }

            $ids = M('newsong_app')->where($where)->getField('newsong_app_id',true);


                if (!empty($ids)){
                    $ids = array_merge($ids);
                for ($i=0;$i<count($ids);$i++){
                    M('newsong_app')->where(array('newsong_app_id'=>$ids[$i]))->setInc('sort');
                }
            }

            $result     =   M('newsong_app')->add($data);



            //记录相关操作日志

            if (!empty($result))
            {
                $msg['state']   =   200;
                $msg['error']   =   '更新添加';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '添加失败';
                $this->ajaxReturn ($msg,'JSON');
            }
        }
        else
        {
            $this->display('game_list_add');
        }
    }


    //游戏题库
    public function game_question()
    {
        $Module         =   M('newsong_questions'); // 实例化User对象
        $count          =   $Module->count();// 查询满足要求的总记录数
        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $field          =   array();
        $data['game_question'] = $Module->field($field)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign('page',$show);// 赋值分页输出
        $this->assign("data",$data);
        $this->display('game_question');
    }

    public function game_question_add()
    {
        if (IS_AJAX) 
        {
            $data['audio']      =   I('post.audio','','htmlspecialchars');
            $data['title']      =   I('post.title','','htmlspecialchars');
            $data['song']       =   I('post.song','','htmlspecialchars');
            $data['singer']     =   I('post.singer','','htmlspecialchars');
            $data['picture']    =   I('post.picture','','htmlspecialchars');
            $data['number']     =   I('post.number','','htmlspecialchars');
            $data['option']     =   I('post.option','','htmlspecialchars');
            $data['music_time'] =   I('post.music_time','','htmlspecialchars');
            $data['aswer_id']   =   I('post.aswer_id','','htmlspecialchars');

            $result     =   M('newsong_questions')->data($data)->add(); // 根据条件更新记录

            //记录相关操作日志

            if (!empty($result)) 
            {
                $msg['state']   =   200;
                $msg['error']   =   '添加成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '添加失败';
                $this->ajaxReturn ($msg,'JSON');
            }
        }
        else
        {
            $this->display('game_question_add');
        }
    }

    public function game_question_edit()
    {

        if (IS_AJAX) 
        {
            $where['id']  =   I('post.id','','htmlspecialchars');
            if (empty($where['id']))
            {
                $msg['state']   =   -1;
                $msg['error']   =   '非法请求';
                $this->ajaxReturn ($msg,'JSON');    
            }

            $data['audio']      =   I('post.audio','','htmlspecialchars');
            $data['title']      =   I('post.title','','htmlspecialchars');
            $data['song']       =   I('post.song','','htmlspecialchars');
            $data['singer']     =   I('post.singer','','htmlspecialchars');
            $data['picture']    =   I('post.picture','','htmlspecialchars');
            $data['number']     =   I('post.number','','htmlspecialchars');
            $data['option']     =   I('post.option','','htmlspecialchars');
            $data['music_time'] =   I('post.music_time','','htmlspecialchars');
            $data['aswer_id']   =   I('post.aswer_id','','htmlspecialchars');


            $result     =   M('newsong_questions')->where($where)->save($data); // 根据条件更新记录

            //记录相关操作日志

            if (!empty($result)) 
            {
                $msg['state']   =   200;
                $msg['error']   =   '更新成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '更新失败';
                $this->ajaxReturn ($msg,'JSON');
            }
        }
        else
        {
            $where['id']  =   I('get.id','','htmlspecialchars');

            if (empty($where['id']))
            {
                $this->error('非法请求');
            }

            $data['game_question']  =   M('newsong_questions')->where($where)->find();

            if ( empty($data)) 
            {
                $this->error('数据不存在');
            }

            $this->assign("data",$data);
            $this->display('game_question_edit');
        }
    }

    //分享微信群
    public function wechat_group()
    {
        $Module         =   M('newsong_wechat_group'); // 实例化对象
        $count          =   $Module->count();// 查询满足要求的总记录数
        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $field          =   array();
        $order_by['id'] =   'desc';
        $data['wechat_group']       =   $Module->field($field)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign('page',$show);// 赋值分页输出
        $this->assign("data",$data);

        $this->display('wechat_group');
    }

    //礼物领取记录(红包)
    public function game_redbag()
    {
        $where = array();
        $where['member_id'] = I('get.uid','','int');
        $where = array_filter($where);

        $Module         =   M('newsong_redbag'); // 实例化对象

        if (empty($where)){
            $count          =   $Module->count();// 查询满足要求的总记录数
        }else {
            $count          =   $Module->where($where)->count();// 查询满足要求的总记录数
        }

        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $field          =   array('challenge_id','red_total','create_time','update_time','status','total_sn','member_id','appid');
        $order_by['challenge_id']   =   'desc';

        if (empty($where)){
            $data['newsong_redbag']     =   $Module->field($field)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();
        }else{
            $data['newsong_redbag']     =   $Module->field($field)->where($where)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();
        }
        $sum = 0;
        foreach ($data['newsong_redbag'] as $key=>$val){

            if ($val['appid']=='wx47f3a2edad028bdf'){
                $data['newsong_redbag'][$key]['title'] = '猜歌名大师奖金版';
            }elseif($val['appid']=='wx370386b7eb0c04bc'){
                $data['newsong_redbag'][$key]['title'] = '空耳军';
            }
            $sum += $val['red_total'];
        }
        $sum = sprintf("%.2f", $sum);
        $this->assign('title','空耳军(猜歌名大师)');
        $this->assign('sum',$sum);// 列总钱数
        $this->assign('name',1);
        $this->assign('page',$show);// 赋值分页输出
        $this->assign("data",$data);

        $this->display('game_redbag');
    }

    //礼物领取记录(红包)
    public function game_redbagplus()
    {

        $where = array();
        $where['member_id'] = I('get.uid','','int');
        $where = array_filter($where);

        $Module         =   M('newsongplus_redbag'); // 实例化对象

        if (empty($where)){
            $count          =   $Module->count();// 查询满足要求的总记录数
        }else {
            $count          =   $Module->where($where)->count();// 查询满足要求的总记录数
        }

        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $field          =   array('challenge_id','red_total','create_time','update_time','status','total_sn','member_id');
        $order_by['challenge_id']   =   'desc';

        if (empty($where)){
            $data['newsong_redbag']     =   $Module->field($field)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();
        }else{
            $data['newsong_redbag']     =   $Module->field($field)->where($where)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();
        }
        $sum = 0;

        foreach ($data['newsong_redbag'] as $key=>$val){

            $data['newsong_redbag'][$key]['title'] = '疯狂猜歌';
            $sum += $val['red_total'];
        }

        $sum = sprintf("%.2f", $sum);

        $this->assign('title','疯狂猜歌');
        $this->assign('sum',$sum);// 列总钱数
        $this->assign('name',2);
        $this->assign('page',$show);// 赋值分页输出
        $this->assign("data",$data);


        $this->display('game_redbag');
    }


    //礼物领取记录(红包)
    public function game_redbagnao()
    {

        $where = array();
        $where['member_id'] = I('get.uid','','int');
        $where = array_filter($where);

        $Module         =   M('naosong_redbag'); // 实例化对象

        if (empty($where)){
            $count          =   $Module->count();// 查询满足要求的总记录数
        }else {
            $count          =   $Module->where($where)->count();// 查询满足要求的总记录数
        }

        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $field          =   array('challenge_id','red_total','create_time','update_time','status','total_sn','member_id');
        $order_by['challenge_id']   =   'desc';
        if (empty($where)){
            $data['newsong_redbag']     =   $Module->field($field)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();
        }else{
            $data['newsong_redbag']     =   $Module->field($field)->where($where)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();
        }
        $sum = 0;

        foreach ($data['newsong_redbag'] as $key=>$val){

            $data['newsong_redbag'][$key]['title'] = '脑筋猜歌';
            $sum += $val['red_total'];
        }
        $sum = sprintf("%.2f", $sum);
        $this->assign('sum',$sum);// 列总钱数
        $this->assign('title','脑筋猜歌');
        $this->assign('name',3);
        $this->assign('page',$show);// 赋值分页输出
        $this->assign("data",$data);


        $this->display('game_redbag');
    }




    /**
     * 推送消息
     */
    public function push_message()
    {
        $data_num   =   $this->message_queue();

        if (!empty($data_num))
        {
            $client = new \swoole_client(SWOOLE_SOCK_TCP);
            //连接到服务器
            if (!$client->connect('127.0.0.1', 9501, 0.5))
            {
                //$this->write("connect failed.");
            }

            $data			=	array();
            $data['game']	=	'guessnewsong';
            $data['action'] =	'Push';

            $msg 			=	serialize($data);

            //向服务器发送数据
            if (!$client->send($msg))
            {
                //$this->write("send ".$msg." failed.");
            }

            //关闭连接
            $client->close();
        }
    }

    /**
     * @return int|string
     * 数据压入redis 队列
     */
    private function message_queue()
    {
        $num            =   0;
        $template_data 	=	M('newsong_template_send')->select();
        if(! empty($template_data))
        {
            $redis = new \Redis();

            $redis->connect('127.0.0.1',6379);

            $access_token = $this->gettoken(self::AppID,self::AppSecret);

            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=$access_token";

            $tem = "K21rIUZuOoy_uz7jUInB9KAarQEdvlZS8XkzomYQ_Lg";

            $fdata = array(
                'keyword1'=>array(
                    'value'=>date('Y-m-d'),
                    'color'=>'#173177',
                ),
                'keyword2'=>array(
                    'value'=>'王俊凯来看你了',
                    'color'=>'#ff0000',
                ),
                'keyword3'=>array(
                    'value'=>'王源也来了',
                    'color'=>'#173177',
                ),

            );

            foreach($template_data as $key=> $value)
            {
                $data = array(
                    'touser'=>$value['touser'],
                    'template_id'=>$tem,
                    'page'=>'pages/index/index',
                    'form_id'=>$value['form_id'],
                    'data'=>$fdata,
                    'emphasis_keyword'=>'keyword2.DATA'
                );

                $post_data 			=	array();
                $post_data['data']	=	$data;
                $post_data['url']	=	$url;

                $redis->rPush('push_message_guessnewsong',json_encode($post_data));

                $key++;
                $num    =   $key;
            }

        }

        return $num;
    }

    //审核中
    public function game_cash()
    {

        if (IS_AJAX){

            $where['id'] = I('post.id','','htmlspecialchars');

            if (empty($where['id']))
            {
                $msg['state']   =   -1;
                $msg['error']   =   '非法请求';
                $this->ajaxReturn ($msg,'JSON');
            }

            $user = M('newsong_cash')->field('uid,money')->where($where)->find();

            $uid = $user['uid'];

            $upchsh = M('newsong_cash')->where($where)->save(array('cash_status'=>'1'));
             M('newsong_member')->where(array('uid'=>$uid))->save(array('lock_money'=>'0'));
            M('newsong_member')->where(array('uid'=>$uid))->setInc('used_money',$user['money']);



            if (!empty($upchsh))
            {
                $msg['state']   =   200;
                $msg['error']   =   '成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '失败';
                $this->ajaxReturn ($msg,'JSON');
            }


        }else{

        $Module         =   M('newsong_cash'); // 实例化对象
        $where['cash_status'] = 0;
        $count          =   $Module->where($where)->count();// 查询满足要求的总记录数
        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $order_by['id']   =   'asc';
        $data     =   $Module->where($where)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();

        foreach ($data as $key=>$val){
            if ($val['appid']=='wx47f3a2edad028bdf'){
                $data[$key]['title'] = '猜歌名大师奖金版';
            }elseif($val['appid']=='wx370386b7eb0c04bc'){
                $data[$key]['title'] = '空耳军';
            }
        }


        $this->assign('page',$show);// 赋值分页输出
        $this->assign('title','空耳君(猜歌名大师)');
            $this->assign('name',1);
        $this->assign("data",$data);
        $this->display('game_cash');
        }
    }

    //审核(疯狂猜歌)
    public function game_cashplus()
    {

        if (IS_AJAX){

            $where['id'] = I('post.id','','htmlspecialchars');

            if (empty($where['id']))
            {
                $msg['state']   =   -1;
                $msg['error']   =   '非法请求';
                $this->ajaxReturn ($msg,'JSON');
            }

            $user = M('newsongplus_cash')->field('uid,money')->where($where)->find();

            $uid = $user['uid'];

            $upchsh = M('newsongplus_cash')->where($where)->save(array('cash_status'=>'1'));
            M('newsongplus_member')->where(array('uid'=>$uid))->save(array('lock_money'=>'0'));
            M('newsongplus_member')->where(array('uid'=>$uid))->setInc('used_money',$user['money']);



            if (!empty($upchsh))
            {
                $msg['state']   =   200;
                $msg['error']   =   '成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '失败';
                $this->ajaxReturn ($msg,'JSON');
            }


        }else{

            $Module         =   M('newsongplus_cash'); // 实例化对象
            $where['cash_status'] = 0;
            $count          =   $Module->where($where)->count();// 查询满足要求的总记录数
            $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
            $show           =   $Page->show();// 分页显示输出

            $order_by['id']   =   'asc';
            $data     =   $Module->where($where)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();
            foreach ($data as $key=>$val){

                $data[$key]['title'] = '疯狂猜歌';

            }

            $this->assign('page',$show);// 赋值分页输出
            $this->assign('title','疯狂猜歌');
            $this->assign('name',2);
            $this->assign("data",$data);
            $this->display('game_cashplus');
        }
    }


    //审核(猜歌巨星)
    public function game_cashstar()
    {

        if (IS_AJAX){

            $where['id'] = I('post.id','','htmlspecialchars');

            if (empty($where['id']))
            {
                $msg['state']   =   -1;
                $msg['error']   =   '非法请求';
                $this->ajaxReturn ($msg,'JSON');
            }

            $user = M('starsong_cash')->field('uid,money')->where($where)->find();

            $uid = $user['uid'];

            $upchsh = M('starsong_cash')->where($where)->save(array('cash_status'=>'1'));
            M('starsong_member')->where(array('uid'=>$uid))->save(array('lock_money'=>'0'));
            M('starsong_member')->where(array('uid'=>$uid))->setInc('used_money',$user['money']);



            if (!empty($upchsh))
            {
                $msg['state']   =   200;
                $msg['error']   =   '成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '失败';
                $this->ajaxReturn ($msg,'JSON');
            }


        }else{

            $Module         =   M('starsong_cash'); // 实例化对象
            $where['cash_status'] = 0;
            $count          =   $Module->where($where)->count();// 查询满足要求的总记录数
            $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
            $show           =   $Page->show();// 分页显示输出

            $order_by['id']   =   'asc';
            $data     =   $Module->where($where)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();


            $this->assign('page',$show);// 赋值分页输出
            $this->assign('title','猜歌巨星');
            $this->assign("data",$data);
            $this->display('game_cashstar');
        }
    }


    //审核(脑筋猜歌)
    public function game_cashnao()
    {

        if (IS_AJAX){

            $where['id'] = I('post.id','','htmlspecialchars');

            if (empty($where['id']))
            {
                $msg['state']   =   -1;
                $msg['error']   =   '非法请求';
                $this->ajaxReturn ($msg,'JSON');
            }

            $user = M('naosong_cash')->field('uid,money')->where($where)->find();

            $uid = $user['uid'];

            $upchsh = M('naosong_cash')->where($where)->save(array('cash_status'=>'1'));
            M('naosong_member')->where(array('uid'=>$uid))->save(array('lock_money'=>'0'));
            M('naosong_member')->where(array('uid'=>$uid))->setInc('used_money',$user['money']);



            if (!empty($upchsh))
            {
                $msg['state']   =   200;
                $msg['error']   =   '成功';
                $this->ajaxReturn ($msg,'JSON');
            }
            else
            {
                $msg['state']   =   -1;
                $msg['error']   =   '失败';
                $this->ajaxReturn ($msg,'JSON');
            }


        }else{

            $Module         =   M('naosong_cash'); // 实例化对象
            $where['cash_status'] = 0;
            $count          =   $Module->where($where)->count();// 查询满足要求的总记录数
            $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
            $show           =   $Page->show();// 分页显示输出

            $order_by['id']   =   'asc';
            $data     =   $Module->where($where)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();
            foreach ($data as $key=>$val){

                $data[$key]['title'] = '脑筋猜歌';

            }

            $this->assign('page',$show);// 赋值分页输出
            $this->assign('title','脑筋猜歌');
            $this->assign('name',3);
            $this->assign("data",$data);
            $this->display('game_cashnao');
        }
    }

    //审核过
    public function game_cash1()
    {

        $Module         =   M('newsong_cash'); // 实例化对象
        $where['cash_status'] = 1;
        $count          =   $Module->where($where)->count();// 查询满足要求的总记录数
        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $order_by['id']   =   'asc';
        $data     =   $Module->where($where)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();

        foreach ($data as $key=>$val){
            if ($val['appid']=='wx47f3a2edad028bdf'){
                $data[$key]['title'] = '猜歌名大师奖金版';
            }elseif($val['appid']=='wx370386b7eb0c04bc'){
                $data[$key]['title'] = '空耳军';
            }
        }

        $this->assign('title','空耳君(猜歌名大师)');
        $this->assign('name',1);


        $this->assign('page',$show);// 赋值分页输出

        $this->assign("data",$data);
        $this->display('game_cash1');
    }

    //审核过
    public function game_cash1plus()
    {

        $Module         =   M('newsongplus_cash'); // 实例化对象
        $where['cash_status'] = 1;
        $count          =   $Module->where($where)->count();// 查询满足要求的总记录数
        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $order_by['id']   =   'asc';
        $data     =   $Module->where($where)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();

        foreach ($data as $key=>$val){

                $data[$key]['title'] = '疯狂猜歌';

        }



        $this->assign('title','疯狂猜歌');
        $this->assign('name',2);

        $this->assign('page',$show);// 赋值分页输出

        $this->assign("data",$data);
        $this->display('game_cash1');
    }

    //审核过
    public function game_cash1nao()
    {

        $Module         =   M('naosong_cash'); // 实例化对象
        $where['cash_status'] = 1;
        $count          =   $Module->where($where)->count();// 查询满足要求的总记录数
        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $order_by['id']   =   'asc';
        $data     =   $Module->where($where)->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();

        foreach ($data as $key=>$val){

            $data[$key]['title'] = '脑筋猜歌';

        }



        $this->assign('title','脑筋猜歌');
        $this->assign('name',3);

        $this->assign('page',$show);// 赋值分页输出

        $this->assign("data",$data);
        $this->display('game_cash1');
    }



    //所有
    public function game_cash2()
    {

        $Module         =   M('newsong_cash'); // 实例化对象

        $count          =   $Module->count();// 查询满足要求的总记录数
        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $order_by['id']   =   'asc';
        $data     =   $Module->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();

        foreach ($data as $key=>$val){
            if ($val['appid']=='wx47f3a2edad028bdf'){
                $data[$key]['title'] = '猜歌名大师奖金版';
            }elseif($val['appid']=='wx370386b7eb0c04bc'){
                $data[$key]['title'] = '空耳军';
            }
        }



        $this->assign('title','空耳君(猜歌名大师)');
        $this->assign('name',1);

        $this->assign('page',$show);// 赋值分页输出

        $this->assign("data",$data);
        $this->display('game_cash2');
    }


    //所有
    public function game_cash2plus()
    {

        $Module         =   M('newsongplus_cash'); // 实例化对象

        $count          =   $Module->count();// 查询满足要求的总记录数
        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $order_by['id']   =   'asc';
        $data     =   $Module->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();

        foreach ($data as $key=>$val){

            $data[$key]['title'] = '疯狂猜歌';

        }

        $this->assign('title','疯狂猜歌');
        $this->assign('name',2);

        $this->assign('page',$show);// 赋值分页输出

        $this->assign("data",$data);
        $this->display('game_cash2');
    }

    //所有
    public function game_cash2nao()
    {

        $Module         =   M('naosong_cash'); // 实例化对象

        $count          =   $Module->count();// 查询满足要求的总记录数
        $Page           =   new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show           =   $Page->show();// 分页显示输出

        $order_by['id']   =   'asc';
        $data     =   $Module->order($order_by)->limit($Page->firstRow.','.$Page->listRows)->select();

        foreach ($data as $key=>$val){

            $data[$key]['title'] = '脑筋猜歌';

        }

        $this->assign('title','脑筋猜歌');
        $this->assign('name',3);

        $this->assign('page',$show);// 赋值分页输出

        $this->assign("data",$data);
        $this->display('game_cash2');
    }



}